home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: artemis.sto.fdata.se!news
- From: Niklas Mellin <niklas.mellin@sto.fdata.se>
- Subject: Re: Question about destructor...
- Sender: news@artemis.sto.fdata.se (UseNet NetNews)
- Message-ID: <30EBD3C5.429C@sto.fdata.se>
- Date: Thu, 4 Jan 1996 13:19:01 GMT
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- References: <4cegke$p5@newsbf02.news.aol.com> <4ces35$3iq$1@mhafn.production.compuserve.com>
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0b4 (WinNT; I)
- Organization: WM-data F÷rsvarsdata AB, Sweden
-
- Nil Bannerjee wrote:
- >
- > If you call the destructor of A from B's destructor then this
- > will take care of the inherited attributes.
- >
- > CB::~CB()
- > {
- > //your stuff..
- > ..
- > ..
- > ~CA();
- > }
-
- WRONG! WRONG! WRONG!
-
- You are lucky that your compiler wont let this through!
- When an object is destroyed all base class destructors will
- be called automatically. You don't have to do anything, and
- you can't prevent it.
-
- If you call the base class' destructor explicitly it will be
- called twice, and the 2nd time will very likely lead to program
- crashes.
-
- The reason the above code does not pass the compliler (at least
- not borland 4.5) is that the form to call the destructor would
- be: (CA*)this->~CA(); But please: don't do this.
-
- ---
- Niklas Mellin
-